var chart;

$(document).ready(function() {
	
	// Average duration of a studentactivity per company
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/get_cat_studentactivity.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/avggotsa_company.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-2',
							defaultSeriesType: 'column',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Durée moyenne d\'une activité universitaire par entreprise</strong>'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Nombre de jours'
							}
						},
						credits: {
							enabled: false
					    },
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});

	// Last 12 months studentactivity
	$.ajax({
		type:	'POST',
		url:	'ajax/stats/get_lastmonths.php',
		success: function(categories){
			$.ajax({
				type:	'POST',
				url:	'ajax/stats/gotsa_company_sa_month.php',
				success: function(ajaxData){
					chart = new Highcharts.Chart({
						chart: {
							renderTo: 'stat-renderer-1',
							defaultSeriesType: 'spline',
							backgroundColor: '#f6f7f8',
							borderColor: '#507aaa',
							borderWidth: 2,
							borderRadius: 0
						},
						title: {
							text: '<strong>Activité universitaire des 12 derniers mois</strong>'
						},
						xAxis: {
							categories: jQuery.parseJSON(categories)
						},
						yAxis: {
							title: {
								text: 'Activité (cumul)'
							}
						},
						tooltip: {
							formatter: function() {
								return '<b>'+ this.series.name +'</b><br/>'+this.x+': '+this.y;
							}
						},
						plotOptions: {
							line: {
								dataLabels: {
									enabled: true
								},
								enableMouseTracking: true
							}
						},
						credits: {
							enabled: false
					    },
						series: jQuery.parseJSON(ajaxData)
					});
				}
			});
		}
	});
});